package com.Test;

import com.dao.MybatisUtil;
import com.dao.StuDao;
import com.entity.Student;
import org.apache.ibatis.session.SqlSession;

import java.sql.Date;
import java.util.List;

public class TestStu {
    public static void main(String[] args) {
        TestStu test = new TestStu();
        test.find();
        // test.add();
        //test.del();
        //test.updt();
       // test.limt();
    }
    //查看全部
    public void find(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        StuDao mapper = sqlSession.getMapper(StuDao.class);
        List<Student> stu = mapper.find();
        for (Student student : stu) {
            System.out.println(student);
        }
        MybatisUtil.close(sqlSession);
    }
    //增加
    public void add(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        StuDao mapper = sqlSession.getMapper(StuDao.class);
        int add = mapper.add(new Student( 2, "猪八戒3", "男", "16666466", "222422", "4444444", "合肥", "肥东", "11331", null, Date.valueOf("2020-10-11"), Date.valueOf("2011-01-12")));
        System.out.println(add);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    //删除
    public void del(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        StuDao mapper = sqlSession.getMapper(StuDao.class);
        int del = mapper.del(new Student(226));
        System.out.println(del);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    //改
    public void updt(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        StuDao mapper = sqlSession.getMapper(StuDao.class);
        int i = mapper.updt(new Student(216, "地狱"));
        System.out.println(i);
        MybatisUtil.commit(sqlSession);
        MybatisUtil.close(sqlSession);
    }
    //分页
    public void limt(){
        SqlSession sqlSession = MybatisUtil.getsqlSession();
        StuDao mapper = sqlSession.getMapper(StuDao.class);
        List<Student> stu = mapper.limt(10, 10);
        for (Student student : stu) {
            System.out.println(student);
        }
        MybatisUtil.close(sqlSession);
    }
    }

